<?php

// +----------------------------------------------------------------------
// |首页服务层
// +----------------------------------------------------------------------

namespace app\common\system;

use app\admin\Model\MenuModel;
use app\admin\Model\AuthGroupsModel;
use think\facade\Db;

class IndexService
{

    /**
     * 获取的菜单的数据
     * @param array $param 前台传过来的参数  
     * @return array
     */
    public static function index($param)
    {
        $MenuModel = new MenuModel();      
        $AuthGroupsModel = new AuthGroupsModel();  
        $params= $param['params'];
        if($params['group_id']){
            //超级管理员拥有拥有全部权限
            $menu = $MenuModel->where(['status' => 1, 'ismenu' => 1])->field('id,pid,title,url,icon,sort')->order('sort asc')->select()->toArray();    
        }else{
              //其他用户组权限验证
              //查询的用户组权限
              $ruels =$AuthGroupsModel->where(['id' => $params['group_id'],'status'=>1])->field('ruels')->find(); 
               if($ruels['ruels']){
                   $ruels= explode(',', $ruels['ruels']);
                   $menu = $MenuModel->where(['status' => 1, 'ismenu' => 1,'id' => ['in', $ruels]])->field('id,pid,title,url,icon,sort')->order('sort asc')->select()->toArray();    
               }else{
                   $menu=[];
               }              
        }
       
        $menu_list = buildTree($menu);
        return $menu_list;

    }
}